<?php

 $backend_user_id = '';
    $createBy = '';
if ($classModel->backend_user_id <> "") {
    $backend_user_id = $classModel->backend_user_id;
} else {
    $createBy = $classModel->users_id;
}

if (getLoginUserId() <> "") {
    $uid = getLoginUserId();
    $user = Users::model()->findByAttributes(array('id' => $uid));
    $email = $user->username;
    $userProfiles = Profiles::model()->findByAttributes(array('user_id' => $uid));
    $name = $userProfiles->first_name . " " . $userProfiles->last_name;
} else {
    $email = '';
    $uid = '';
    $name = '';
}
$form = $this->beginWidget('GxActiveForm', array(
    'id' => 'make-query-form',
    'action' => Yii::app()->createUrl('MakeQuery/Create'),
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
        'validateOnChange' => true,
        'enableAjaxValidation' => true,
    ),
        ));
?>
<div class="padding20px">
    <div class="common">
        <h3 class="remmarginT font-opensanslt txtfff fnt-size18 linHnml addpaddingB10">Make Query</h3>
        <input name="MakeQuery[courses_id]" id="MakeQuery_classes_id" value="<?php echo $classModel->id; ?>" type="hidden" />
        <input name="MakeQuery[users_id]" id="MakeQuery_users_id" value="<?php echo $uid; ?>" type="hidden" />
        <input name="MakeQuery[created_by]" id="MakeQuery_created_by" value="<?php echo $createBy; ?>" type="hidden" />
        <input name="MakeQuery[backend_user_id]" id="MakeQuery_created_by" value="<?php echo $backend_user_id; ?>" type="hidden" />
        <label for="MakeQuery_name">Name <span class="required">*</span></label>
        <?php echo $form->textField($model, 'name', array('maxlength' => 45, 'class' => 'field', 'value' => $name, 'placeholder' => 'First Name Last Name')); ?>
        <?php echo $form->error($model, 'name'); ?>
    </div>
    <div class="common">
        <label for="MakeQuery_email">Email <span class="required">*</span></label>
        <?php echo $form->textField($model, 'email', array('maxlength' => 45, 'class' => 'field', 'readonly' => 'readonly', 'value' => $email, 'placeholder' => 'Email')); ?>
        <?php echo $form->error($model, 'email'); ?>
    </div>
    <div class="common">
        <label>Phone Number<em title="Your Phone number" class="sprite question-sign">&nbsp;</em></label>
        <?php echo $form->textField($model, 'phone', array('maxlength' => 45, 'class' => 'field', 'placeholder' => 'Phone')); ?>
        <?php echo $form->error($model, 'phone'); ?>
    </div>
    <div class="common">
        <div class="timef">
            <label>Time Slot<em title="Choose Time Slot for trainer to contact you" class="sprite question-sign">&nbsp;</em></label>
            <div id="timing">
                <select name="TimingMakequery[time_from][]" class="timeFrom"><?php numberofTimingsFrame(); ?></select>
                <select name="TimingMakequery[time_to][]" class="timeTo"><?php numberofTimingsFrame(); ?></select>
            </div>
            <input type="hidden" name="numrow" id="numrow" value="1" />
            <span class="inline-block"><a href="javascript:void(0);" onclick="addRowTiming();" class="fontColor">+ Add additional time slots</a></span>
        </div>   
    </div>
    <div class="common">
        <label for="MakeQuery_query">Query <span class="required">*</span></label>
        <?php echo $form->textArea($model, 'query'); ?>
        <?php echo $form->error($model, 'query'); ?>
    </div>
    <div class="common">
        <p id="AjaxLoaderMakeQ-formResult" style="font-size: 15px;color: #fff;display: none;"></p>
        <div class="height1px borB rempaddingB"></div>
    </div>
   <p class="alignR remmarginB">
   <span id="AjaxLoaderMakeQ"  style="display:none;"><img src="<?php echo ThemePath(); ?>/images/ajax-loader-mini.gif"></img></span>
   
        <?php
        //if(getLoginUserId()<>""){
        echo CHtml::ajaxSubmitButton('Submit', CHtml::normalizeUrl(array('MakeQuery/create')), array(
            'dataType' => 'json',
            'type' => 'post',
            'success' => 'function(data) {
                        $("#AjaxLoaderMakeQ").hide(); 
						if(data.status == "nologin"){openLogin();}
						
                        if(data.status != "nologin"){
						if(data.status=="sameuser"){
						$("#AjaxLoaderMakeQ-formResult").show();
                        $("#AjaxLoaderMakeQ-formResult").html("<p>You can not make query for own class.</p>");
						}else{
						 if(data.status=="success"){
                        $("#AjaxLoaderMakeQ-formResult").show();
                        $("#AjaxLoaderMakeQ-formResult").html("Your Query submitted successfully.");
                        } else{
                         $.each(data, function(key, val) {   
                        $("#"+key+"_em_").text(val);                                                    
                        $("#"+key+"_em_").show();
                        $("#MakeQuery .common").css("margin-bottom","0px");
                        });
                        }
						}
						}
                    }',
            'beforeSend' => 'function(){                        
                           $("#AjaxLoaderMakeQ").show();
                      }'
                ), array('class' => 'btnbook', 'name' => 'makeQId', 'id' => 'makeQId'));
        echo CHtml::ajaxSubmitButton('Submit', CHtml::normalizeUrl(array('MakeQuery/create')), array(
            'dataType' => 'json',
            'type' => 'post',
            'success' => 'function(data) {
                        $("#AjaxLoaderMakeQ").hide();  
                        if(data.status=="sameuser"){
						$("#AjaxLoaderMakeQ-formResult").show();
                        $("#AjaxLoaderMakeQ-formResult").html("<p>You can not make query for own class.</p>");
						}else{
						if(data.status=="success"){
                        $("#AjaxLoaderMakeQ-formResult").show();
                        $("#AjaxLoaderMakeQ-formResult").html("Your Query submitted successfully.");
                        $(".alignR").html("&nbsp;");
						} else{
                        $.each(data, function(key, val) {   
                        $("#"+key+"_em_").text(val);                                                    
                        $("#"+key+"_em_").show();
                        $("#MakeQuery .common").css("margin-bottom","0px");
                        });
                        }
						}
                    }',
            'beforeSend' => 'function(){                        
                           $("#AjaxLoaderMakeQ").show();
                      }'
                ), array('class' => 'btnbook', 'name' => 'makeQIdok', 'id' => 'makeQIdok', 'style' => 'display:none;'));
        ?>
    </p>
</div>
<?php
$this->endWidget();
?>

<!--Sign Up Form Popup-->
<div id="loginPop" class="pop-out mfp-hide">
<?php  Yii::app()->getModule('user'); $this->renderPartial('application.modules.user.views.user.loginpop'); ?>
</div>
<!--End Sign Up Form Popup-->

<script type="text/javascript" src="<?php echo ThemePath(); ?>/js/jquery.lightbox_me.js"></script>

<script>

function openLogin(){
$.magnificPopup.open({
    items: [{src: '#loginPop', type: 'inline'} ],
    gallery: {enabled: true},
	mainClass: 'mfp-fade',
	removalDelay: 160,
    type: 'image'
    });
}


/*	$('.signupCall').magnificPopup({
    items: [{src: '#makeQId', type: 'inline'} ],
    gallery: {enabled: true},
	mainClass: 'mfp-fade',
	removalDelay: 160,
    type: 'image'
});
$('.loginCall').magnificPopup({
    items: [{src: '#loginPop', type: 'inline'} ],
    gallery: {enabled: true},
	mainClass: 'mfp-fade',
	removalDelay: 160,
    type: 'image'
});*/
</script>

<script type="text/javascript">
    var rowNum = 0;
    function addRowTiming() {
        rowNum = $("#numrow").val();
        if(rowNum<5){
            rowNum ++;
            var row = '<div id="rowNum'+rowNum+'"><select class="timeFrom'+rowNum+'" name="TimingMakequery[time_from][]"><?php numberofTimingsFrame(); ?></select>&nbsp;<select class="timeTo'+rowNum+'" name="TimingMakequery[time_to][]"><?php numberofTimingsFrame(); ?></select><p class="alignL padding20px remmarginB"><a href="javascript:void(0)" class="fontColor" onclick="removeRowTiming('+rowNum+');">-Remove Time Slot</a></p></div>';
            jQuery('#timing').append(row);
            $(".timeFrom"+rowNum).fancyfields();
            $(".timeTo"+rowNum).fancyfields();
            $("#numrow").val(rowNum);
        }
    }

    function removeRowTiming(rowNum) {
        jQuery('#rowNum'+rowNum).remove();
        var numTextval = $("#numrow").val();
        numTextval = numTextval-1;
        $("#numrow").val(numTextval);
    }

</script>